<?php
require_once("../../config/config.inc.php");
///require_once("task_function.php");

$sUserID   = $SEC->sUserID;
$sUsername = $SEC->sUserName;
$sRole     = $SEC->sRole;
$sProjectID = $_SESSION["task_project_id"];
$sTaskID    = fn_getParam("strTaskID","");
$isEnableEdit = false; //控制总体的编辑状态

if (empty($sProjectID) || $sProjectID == null) {
	return;
}

//获取企业日历信息
$sql  = "SELECT WORKDAY,AMSTARTTIME,AMENDTIME,PMSTARTTIME,PMENDTIME,STARTDATE,FINISHDATE,USERNAME,MANAGER,ISPERSONAL ";
$sql .= "FROM $TABLE_PROJECT ";
$sql .= "WHERE ID='".$sProjectID."'";
$stmt = $DB->query($sql);
if ($aProject = $DB->fetchArray($stmt)) {
    $aProject["WORKDAY"]     = fn_isNull($aProject["WORKDAY"],"0111110");
    $aProject["AMSTARTTIME"] = fn_isNull($aProject["AMSTARTTIME"],"09:00");
    $aProject["AMENDTIME"]   = fn_isNull($aProject["AMENDTIME"]  ,"12:00");
    $aProject["PMSTARTTIME"] = fn_isNull($aProject["PMSTARTTIME"],"13:00");
    $aProject["PMENDTIME"]   = fn_isNull($aProject["PMENDTIME"]  ,"18:00");
    $SM->assign("aProject",$aProject);

    //只要当前用户是项目负责人，或者项目是当前用户创建的，
    //或者当前用户是系统管理且项目的开放级别是在单位内公开的，才可以编辑。
    if ($aProject["USERNAME"]==$sUsername || $aProject["MANAGER"]==$sUsername) {
        $isEnableEdit = true;
    } else {
        $isEnableEdit = false;
    }
}
$_SESSION["task_enable_editall"] = ($isEnableEdit?"editall":"none");
$DB->freeResult($stmt);

$aTask = array();
$aTask["ID"] = $sTaskID;
$aTask["PLANSTARTDATE"] = date("Y-m-d");   //任务计划开始时间
$aTask["PLANFINISHDATE"]= date("Y-m-d",strtotime(date("Y-m-d"))+24*60*60);   //任务计划完成时间
$aTask["LIMITTYPE"]     = "8";  //设置默认值
$aTask["TASKTYPE"]      = "1";  //设置默认值
$aTask["PRIORITY"]      = "2";  //任务优先级


$SM->assign("aTask",$aTask);
$SM->assign("sTaskType"     ,$DICT->getComboStore("BASE_TASK_TYPE",false));
$SM->assign("sTaskLimitType",$DICT->getComboStore("BASE_TASK_LIMITTYPE",false));
$SM->assign("sImportance"   ,$DICT->getComboStore("BASE_IMPORTANCE",false));
$SM->assign("sPreTaskType"  ,$DICT->getComboStore("BASE_PRETASK_TYPE",false));
$SM->assign("sUsername"     ,$sUsername);

if ($isEnableEdit)
    $SM->display('task/task.html');
else
    $SM->display('task/taskinfo.html');
?>